/*
 * @Author: 李环玉 834654733@qq.com
 * @Date: 2023-12-17 18:10:28
 * @LastEditors: 李环玉 834654733@qq.com
 * @LastEditTime: 2024-01-13 01:30:50
 * @FilePath: \koa-server\src\service\blogComment.service.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

const blogComment = require('../model/blogComment.model')
const Blog = require('../model/blog.model')
class blogCommentService {
  async getBlogComment(params){
    const json = await blogComment.findAll(
      { where:{ rId:params.id, pId:null },
      include : {
        model: blogComment,
        as:'children', 
        required : false,
        include : {
          model: blogComment,
          all : true,
          nested : true,
          include : {
            all : true,
            nested : true,
            include : {
              all : true,
              nested : true,
              include : {
                all : true,
                nested : true,
                include : {
                  all : true,
                  nested : true,
                  include : {
                    all : true,
                    nested : true,
                    include : {
                      all : true,
                      nested : true,
                    }
                  }
                }
              }
            }
          }
        }
      }
    })
    return json
  }
  async insertBlogComment(params){
    const jane = await blogComment.create(params);
    const bdata = await Blog.findOne(
      { where:{id:params.rId} }
  )
    await Blog.update(
      { comment: Number(bdata.comment)  + 1 },
      { where:{ id:params.rId } }
    )
    if(jane){
      return true
    } else {
      return false
    }
  }
}

module.exports = new blogCommentService()